class Solution {
public:
    int finalPositionOfSnake(int n, vector<string>& commands) {
        int i = 0, j = 0;
        for(auto s:commands){
            switch(s[0])
            {
                case 'U': i--; break; 
                case 'D': i++; break;
                case 'R': j++; break;
                case 'L': j--; break;
            }
        }
        return i * n + j;
    }
};